
package net.eascn.babyClone.commands
{
	import com.adobe.cairngorm.commands.ICommand;
	import com.adobe.cairngorm.control.CairngormEvent;
	
	import flash.events.Event;
	
	import mx.controls.Alert;
	import mx.core.Application;
	import mx.rpc.IResponder;
	import mx.rpc.events.ResultEvent;
	
	import net.eascn.babyClone.business.*;
	import net.eascn.babyClone.model.ModelLocator;

	public class GetAlbumDefinedCommand implements ICommand, IResponder
	{
		// attributes ============================
		private var model : ModelLocator = ModelLocator.getInstance();
		private var _GetAlbumDefinedDelegate:GetAlbumDefinedDelegate = new GetAlbumDefinedDelegate(this as IResponder);



		// functions ============================
		public function execute( event:CairngormEvent ) : void
		{
			var exml:XML = event.data as XML;
			var url:String = String(exml.@source);
			if(url.length==0)
			{
				Alert.show('相册模板配置文件URL缺失');
				return;
			}
			model.selectAlbumTemplateXML = exml;
			
			_GetAlbumDefinedDelegate.getAlbumDefined(String(exml.@source));
			
			
		}
		
		//----------------------------------------------------------------------------
		public function result( data:Object ) : void
		{
			var resultXML:XML  = ResultEvent(data).result as XML;
			
			if(String(resultXML.@id) != String(model.selectAlbumTemplateXML.@id))
				return;

			model.currentAlbumXML  = resultXML.copy();
			Application.application.dispatchEvent(new Event('currentAlbumXML'));
			model.selectAlbumTemplateXML = resultXML.copy();
			
//			for each(var xml:XML in model.currentAlbumXML.page)
//			{
//				model.currentAlbumXMLListCollection.addItem(xml);
//			}
//			model.currentAlbum = 	VoXMLUtil.parseAlbumDefinedDescXML(resultXML);
//			model.currentRuntimePages = model.currentAlbum.pages;
			
		}
		
		//----------------------------------------------------------------------------
		public function fault( info : Object ) : void
		{
			
			Alert.show(info.toString());
			
		}

	}
}